<!DOCTYPE html>
<html>
<head>
    <title>AI教学助手测试页面</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            line-height: 1.6;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, select, textarea {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        textarea {
            min-height: 150px;
            resize: vertical;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            border: none;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        .result {
            margin-top: 20px;
            border: 1px solid #ddd;
            padding: 15px;
            white-space: pre-wrap;
            background-color: #f8f8f8;
        }
        h2 {
            border-bottom: 2px solid #4CAF50;
            padding-bottom: 10px;
        }
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0,0,0,0.4);
        }
        .modal-content {
            background-color: #fefefe;
            margin: 10% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 80%;
            max-width: 700px;
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }
        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>AI教学助手测试页面</h1>
        
        <h2>生成教学计划</h2>
        <form id="planForm">
            <div class="form-group">
                <label for="subject">学科：</label>
                <input type="text" id="subject" name="subject" value="数学" required>
            </div>
            <div class="form-group">
                <label for="grade">年级：</label>
                <input type="text" id="grade" name="grade" value="初中一年级" required>
            </div>
            <div class="form-group">
                <label for="topic">主题：</label>
                <input type="text" id="topic" name="topic" value="一元一次方程" required>
            </div>
            <button type="button" onclick="generatePlan()">生成教学计划</button>
        </form>
        <div id="planResult" class="result"></div>
        
        <h2>生成练习题</h2>
        <form id="exerciseForm">
            <div class="form-group">
                <label for="exTopic">主题：</label>
                <input type="text" id="exTopic" name="topic" value="一元一次方程" required>
            </div>
            <div class="form-group">
                <label for="difficulty">难度：</label>
                <select id="difficulty" name="difficulty" required>
                    <option value="初级">初级</option>
                    <option value="中等" selected>中等</option>
                    <option value="高级">高级</option>
                </select>
            </div>
            <button type="button" onclick="generateExercises()">生成练习题</button>
        </form>
        <div id="exerciseResult" class="result"></div>
        
        <h2>学生水平分析</h2>
        <form id="analysisForm">
            <div class="form-group">
                <label for="studentId">学生ID：</label>
                <input type="text" id="studentId" name="studentId" value="123" required>
            </div>
            <div class="form-group">
                <label for="anaSubject">学科：</label>
                <input type="text" id="anaSubject" name="subject" value="数学" required>
            </div>
            <button type="button" onclick="analyzeStudent()">分析学生水平</button>
        </form>
        <div id="analysisResult" class="result"></div>
        
        <h2>智能学情分析</h2>
        <button type="button" onclick="openAnalysisModal()">进行智能学情分析</button>
        <div id="classAnalysisResult" class="result"></div>
    </div>
    
    <!-- 学情分析弹窗 -->
    <div id="analysisModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeAnalysisModal()">&times;</span>
            <h2>学情分析数据输入</h2>
            <form id="classAnalysisForm">
                <div class="form-group">
                    <label for="classGrade">年级：</label>
                    <select id="classGrade" name="grade" required>
                        <option value="一年级">一年级</option>
                        <option value="二年级">二年级</option>
                        <option value="三年级">三年级</option>
                        <option value="四年级">四年级</option>
                        <option value="五年级">五年级</option>
                        <option value="六年级">六年级</option>
                        <option value="初中一年级">初中一年级</option>
                        <option value="初中二年级">初中二年级</option>
                        <option value="初中三年级">初中三年级</option>
                        <option value="高中一年级">高中一年级</option>
                        <option value="高中二年级">高中二年级</option>
                        <option value="高中三年级">高中三年级</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="className">班级：</label>
                    <input type="text" id="className" name="className" placeholder="例如：1班、2班" required>
                </div>
                <div class="form-group">
                    <label for="classSubject">学科：</label>
                    <select id="classSubject" name="subject" required>
                        <option value="语文">语文</option>
                        <option value="数学" selected>数学</option>
                        <option value="英语">英语</option>
                        <option value="物理">物理</option>
                        <option value="化学">化学</option>
                        <option value="生物">生物</option>
                        <option value="历史">历史</option>
                        <option value="地理">地理</option>
                        <option value="政治">政治</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="testData">考试情况数据：</label>
                    <textarea id="testData" name="testData" placeholder="请输入学生考试情况数据，例如：
张三，89分，第2题错误，第5题错误，偏科...
李四，76分，第1题错误，第3题错误，计算能力弱...
王五，92分，基础扎实，应用题弱..." required></textarea>
                </div>
                <button type="button" onclick="submitClassAnalysis()">提交分析</button>
            </form>
        </div>
    </div>

    <script>
        function generatePlan() {
            const subject = document.getElementById('subject').value;
            const grade = document.getElementById('grade').value;
            const topic = document.getElementById('topic').value;
            
            fetch(`/api/teaching/plan?subject=${encodeURIComponent(subject)}&grade=${encodeURIComponent(grade)}&topic=${encodeURIComponent(topic)}`, {
                method: 'POST'
            })
            .then(response => response.json())
            .then(data => {
                document.getElementById('planResult').textContent = JSON.stringify(data, null, 2);
            })
            .catch(error => {
                document.getElementById('planResult').textContent = 'Error: ' + error;
            });
        }
        
        function generateExercises() {
            const topic = document.getElementById('exTopic').value;
            const difficulty = document.getElementById('difficulty').value;
            
            fetch(`/api/teaching/exercises?topic=${encodeURIComponent(topic)}&difficulty=${encodeURIComponent(difficulty)}`, {
                method: 'POST'
            })
            .then(response => response.text())
            .then(data => {
                document.getElementById('exerciseResult').textContent = data;
            })
            .catch(error => {
                document.getElementById('exerciseResult').textContent = 'Error: ' + error;
            });
        }
        
        function analyzeStudent() {
            const studentId = document.getElementById('studentId').value;
            const subject = document.getElementById('anaSubject').value;
            
            fetch(`/api/teaching/student-analysis?studentId=${encodeURIComponent(studentId)}&subject=${encodeURIComponent(subject)}`)
            .then(response => response.text())
            .then(data => {
                document.getElementById('analysisResult').textContent = data;
            })
            .catch(error => {
                document.getElementById('analysisResult').textContent = 'Error: ' + error;
            });
        }
        
        // 打开学情分析弹窗
        function openAnalysisModal() {
            document.getElementById('analysisModal').style.display = 'block';
        }
        
        // 关闭学情分析弹窗
        function closeAnalysisModal() {
            document.getElementById('analysisModal').style.display = 'none';
        }
        
        // 提交班级学情分析
        function submitClassAnalysis() {
            const grade = document.getElementById('classGrade').value;
            const className = document.getElementById('className').value;
            const subject = document.getElementById('classSubject').value;
            const testData = document.getElementById('testData').value;
            
            // 准备请求数据
            const requestData = {
                grade: grade,
                className: className,
                subject: subject,
                testData: testData
            };
            
            // 获取token
            const token = localStorage.getItem('token');
            const headers = {
                'Content-Type': 'application/json'
            };
            
            // 如果有token，添加到headers
            if (token) {
                headers['Authorization'] = `Bearer ${token}`;
            } else {
                // 如果没有token，显示提示并返回
                document.getElementById('classAnalysisResult').textContent = '请先登录后再使用此功能';
                closeAnalysisModal();
                return;
            }
            
            // 发送请求到后端
            fetch('/api/teaching/student-analysis/submit', {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(requestData)
            })
            .then(response => {
                if (response.status === 401) {
                    // 如果返回401，提示用户登录
                    document.getElementById('classAnalysisResult').textContent = '登录已过期，请重新登录';
                    return null;
                }
                return response.json();
            })
            .then(data => {
                if (data) {
                    // 关闭弹窗并显示结果
                    closeAnalysisModal();
                    document.getElementById('classAnalysisResult').textContent = data.data;
                }
            })
            .catch(error => {
                document.getElementById('classAnalysisResult').textContent = 'Error: ' + error;
            });
        }
        
        // 点击窗口外部时关闭弹窗
        window.onclick = function(event) {
            const modal = document.getElementById('analysisModal');
            if (event.target == modal) {
                modal.style.display = 'none';
            }
        }
    </script>
</body>
</html> 